# -*- coding: utf-8 -*-
"""
  @Time    : 2024/2/29 11:04
  @Author  : 
  @email   : 
  @File    : task.py
"""
from flask import Blueprint, jsonify
from extensions import scheduler


# 定义蓝图，路由分组
task_bp = Blueprint('task_bp', __name__, url_prefix='/tasks')

@task_bp.route('/list')
def get_tasks():
    task_list = []
    for job in scheduler.get_jobs():
        tmp_dict = {}
        tmp_dict['id'] = str(job.id)
        tmp_dict['name'] = str(job.name)
        tmp_dict['trigger'] = str(job.trigger)
        tmp_dict['next_run_time'] = str(job.next_run_time)
        task_list.append(tmp_dict)
    task_list.sort(key=lambda x: x['id'])
    return jsonify(task_list)
